#include<bits/stdc++.h>

using namespace std;

using ll=long long;
#define endl '\n'
const int maxn = 4;
int n = 4, m = 4;

char G[maxn][maxn] = {
        'A', 'B', '/', 'D',
        'E', 'F', '/', 'H',
        'I', '/', 'K', 'L',
        'M', 'N', 'O', 'P',
};
int book[maxn][maxn];
int dp[maxn][maxn];
int fx[4][2] = {{0,  1},
                {0,  -1},
                {1,  0},
                {-1, 0}};

void bfs(int x, int y) {//O(m*n)
    queue<pair<int, int>> Q;
    Q.push(make_pair(x, y));
    dp[x][y]=0;//自己到自己的距离为0
    book[x][y] = 1;
    while (Q.size()) {
        auto pt = Q.front();
        int hx = pt.first;
        int hy = pt.second;
        int z= dp[hx][hy];
        //cout << G[hx][hy];
        Q.pop();
        for (int i = 0; i < 4; i++) {
            int nx = hx + fx[i][0];
            int ny = hy + fx[i][1];
            if (nx < 0 || nx >= 4 || ny < 0 || ny >= 4 || G[nx][ny] == '/' || book[nx][ny])continue;
            Q.push(make_pair(nx, ny));
            book[nx][ny] = 1;
            dp[nx][ny]=z+1;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int sx=0,sy=0,ex=n-1,ey=m-1;
    bfs(sx,sy);
    cout<<dp[ex][ey];
    return 0;
}
